/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mvp.algorithms.unions;

/**
 *
 * @author WORKSPOT2
 */
public class QuickFind extends AbstractUnionAlgorithm
{

    public QuickFind(int numberOfObjects)
    {
        super(numberOfObjects);
    }
    
    @Override
    public boolean isConnected(int p, int q)
    {
        return id[p]==id[q];
    }

    @Override
    public void union(int p, int q)
    {
        int pid = id[p];
        int qid = id[q];
        for (int i = 0; i < id.length; i++)
        {
            if (id[i] == pid)
            {
                id[i] = qid;
            }
        }
    }
}
